func permuteUnique(nums []int) (result [][]int) {
    sort.Ints(nums)
    n := len(nums)
    temp := []int{}
    visited := make([]bool, n)
    var backtrack func(int)
    backtrack = func(index int) {
        if index == n {
            result = append(result, append([]int(nil), temp...))
            return
        }
        for i, v := range nums {
            if visited[i] || i > 0 && !visited[i-1] && v == nums[i-1] {
                continue
            }
            temp = append(temp, v)
            visited[i] = true
            backtrack(index + 1)
            visited[i] = false
            temp = temp[:len(temp)-1]
        }
    }
    backtrack(0)
    return
}
